package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 设备类型枚举
 */
public enum EquipmentType implements BaseCodeEnum<String> {

    TRANSFORMER("Transformer", "变压器"),
    CABINET("Cabinet", "配电柜"),
    SWITCHGEAR("Switchgear", "开关柜"),
    GENERATOR("Generator", "发电机"),
    UPS("UPS", "不间断电源"),
    PDU("PDU", "电源分配单元"),
    METER("Meter", "电表"),
    SENSOR("Sensor", "传感器"),
    BUSWAY("Busway", "母线槽"),
    DISTRIBUTION_BOX("DistributionBox", "配电箱"),
    CAPACITOR_BANK("CapacitorBank", "电容器组"),
    MOTOR("Motor", "电动机"),
    LIGHTING_PANEL("LightingPanel", "照明配电箱"),
    TRANSFER_SWITCH("TransferSwitch", "双电源切换开关"),
    SURGE_PROTECTOR("SurgeProtector", "浪涌保护器");

    @EnumValue
    private final String code;
    private final String displayName;

    EquipmentType(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    /**
     * 根据 code 获取枚举实例
     */
    public static EquipmentType of(String code) {
        for (EquipmentType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 判断 code 是否有效
     */
    public static boolean isValid(String code) {
        return of(code) != null;
    }
}